from flask import Blueprint, render_template, request, url_for, redirect
from werkzeug.utils import secure_filename
from os import path

data_bp = Blueprint('data', __name__)  # 蓝图用来挂载路由路径data


@data_bp.route('/upload', methods=['GET', 'POST'])
def upload():
    if request.method == 'POST':
        f = request.files['file']
        basepath = path.abspath("./")
        upload_path = path.join(basepath, 'static\\uploads', secure_filename(f.filename))
        imgpath = path.join('/static/uploads', f.filename)
        f.save(upload_path)
        print(imgpath)
        return render_template("upload2.html", message="上传成功", imgpath=imgpath)
    return render_template("upload.html")